package com.wz.jiangsu.main.lock;

public class OddEvenWithJoin {
    public static void main(String[] args) {
        Thread oddThread = new Thread(() -> printNumbers(1, 9, 2), "OddThread");
        Thread evenThread = new Thread(() -> printNumbers(2, 9, 2), "EvenThread");

        try {
            // 启动奇数线程并等待其完成
            oddThread.start();
            oddThread.join();

            // 启动偶数线程并等待其完成
            evenThread.start();
            evenThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void printNumbers(int start, int end, int step) {
        for (int i = start; i <= end; i += step) {
            System.out.println(Thread.currentThread().getName() + ": " + i);
        }
    }
}